<template>
	<!-- 回库 -->
	<view class="outInventory2">
		<view class="in_storageMain animate__animated animate__fadeIn">
			<view class="in_storageMain1">
				<view class="text">名称：</view>
				<input type="text" v-model="items.name" style="color: #b8b8b8" />
			</view>
			<view class="in_storageMain1">
				<view class="text">
					数量：
					<view class="text2" @click="copyNumber(items.number)">预计剩余：{{ items.number }}</view>
				</view>

				<input type="number" :style="{ color: costColor }" v-model="inputs.number" @input="payMentVerfiy" />
			</view>

			<button class="submit" @click="submit">退回</button>
		</view>
	</view>
</template>

<script>
import { request } from '../../request';
import 'animate.css';
export default {
	data() {
		return {
			costColor: '#000000',
			inputs: {
				id: null,
				project: null,
				number: null
			},
			items: {
				name: null,
				number: null
			},
			two: false
		};
	},
	methods: {
		// 检测输入值的状态
		payMentVerfiy() {
			const number = parseFloat(this.inputs.number);
			if (this.items.number < number) {
				this.costColor = '#d04624';
			} else {
				this.costColor = '#000000';
			}
		},
		// 复制数字到输入框
		copyNumber(item) {
			this.inputs.number = item;
		},
		onPickerChange(e) {
			const index = e.detail.value; // 获取选中的索引
			this.selectedOption = this.options2[index]; // 更新选中的值
			this.inputs.project = this.options1[index];
		},
		submit() {
			const number = parseFloat(this.inputs.number);
			request(`public/outPutComponentPart?id=${this.inputs.id}&project=${this.inputs.project}&number=${this.inputs.number}`, {}, 'POST').then((res) => {
				if (res.data.code != 200) {
					this.$message.error('   ' + res.data.msg);
					return;
				}
				// 是否返回两页
				if (this.two) {
					uni.navigateBack({
						delta: 2
					});
				} else {
					uni.navigateBack();
				}
			});
		},
		onLoad(item) {
			request('public/selectComponentById', { id: item.id }, 'GET').then((res) => {
				this.items = res.data.data;
				this.inputs.id = this.items.id;

				// 初始数量
				this.inputs.number = this.items.number;
			});

			// 是否返回两页
			if (item.two != null && item.two) {
				this.two = true;
			}
		},
		onShow() {
			// 获取仓库（公司的那个）
			request('public/selectWarehouse', {}, 'GET').then((res) => {
				// 后续再处理
				if (res.data.code != 200) {
					this.$message.error('   ' + res.data.msg);
					return;
				}
				console.log('仓库Id' + res.data.data.id);
				this.inputs.project = res.data.data.id;
			});
		}
	}
};
</script>

<style scoped>
.text2 {
	float: right;
	font-size: 26rpx;
	color: #b0b0b0;
	padding: 0 0 20rpx 0;
}
.outInventory2 {
	display: flex;
	justify-content: center;
	padding: 40rpx 20rpx;
	background-color: #f8f9fa;
	min-height: 1370rpx;
}

.in_storageMain {
	width: 100%;
	max-width: 650rpx;
	background-color: #ffffff;
	border-radius: 20rpx;
	padding: 40rpx 30rpx;
	box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.08);
	height: 700rpx;
	margin-top: 200rpx;
}

.in_storageMain1 {
	width: 100%;
	margin: 30rpx 0;
	display: flex;
	flex-direction: column;
}

.text {
	font-size: 28rpx;
	color: #666666;
	margin-bottom: 15rpx;
	font-weight: 500;
}

input,
.picker {
	width: 92%;
	height: 80rpx;
	border-radius: 12rpx;
	border: 1px solid #e0e0e0;
	padding: 0 25rpx;
	font-size: 28rpx;
	color: #333333;
	transition: all 0.2s ease;
}

input:focus,
.picker:focus {
	border-color: #3498db;
	box-shadow: 0 0 0 2rpx rgba(52, 152, 219, 0.2);
}

.picker {
	display: flex;
	align-items: center;
	background-color: #ffffff;
	position: relative;
}

.picker::after {
	content: '▾';
	position: absolute;
	right: 25rpx;
	color: #999999;
}

.addBill {
	margin-top: 15rpx;
	padding: 15rpx 25rpx;
	background-color: #3498db;
	color: #ffffff;
	border-radius: 10rpx;
	font-size: 26rpx;
	text-align: center;
	transition: all 0.2s ease;
}

.addBill:hover {
	background-color: #2980b9;
}

.BillSelect {
	height: 80rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
}
.BillSelect button {
	margin: 0;
	height: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
}

.BillSelect .picker {
	width: 440rpx !important;
}

.beizhu {
	width: 92%;
	height: 200rpx;
	padding: 20rpx 25rpx;
	border-radius: 12rpx;
	border: 1px solid #e0e0e0;
	font-size: 28rpx;
	color: #333333;
	transition: all 0.2s ease;
	resize: none;
}

.beizhu:focus {
	border-color: #3498db;
	box-shadow: 0 0 0 2rpx rgba(52, 152, 219, 0.2);
}
.submit {
	background-color: #2fb0bc;
	color: white;
	border: 0;
	margin-top: 100rpx;
}
.cost {
	width: ;
}
.cost::after {
	content: '元';
	position: absolute;
	right: 50rpx;
	margin-top: -40rpx;
	transform: translateY(-50%);
	color: #999;
	pointer-events: none;
}
</style>
